import requests

# url = 'https://www.mms591.com/www.mms591.com-photo/20200815/1-200Q5160P2_480x800.jpg'
# url1 = 'https://www.baidu.com/'
#
# #res.encoding = 'utf-8'
# res = requests.get(url)
# print(res.url)#打印响应对象的url
# print(res.request.headers)#打印响应对象的请求头
# print(res.headers)#打印响应头
# print(res.cookies)#打印响应对象的cookies
# print(res.status_code)#打印响应对象的状态
#
# res1 = requests.get(url1)
# #wb是以二进制的方式写入
# with open('谭志郎.jpg','wb') as f:
#     f.write(res.content)
#
# #响应的保存
# with open('baidu.html','w',encoding='utf-8') as f:
#     f.write(res1.content.decode())#decode()解码(默认utf-8解码)  encode()是编译成为二进制码

#请求头中的user-agent字段必不可少,模拟浏览器,表示客户端的操作系统以及浏览器的信息
url = 'https://www.baidu.com/'

#构建请求头
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0'
}
#发送请求
response = requests.get(url,headers=headers)
print(response.request.headers)#响应对象的请求头
# print(response.content.decode())
# print(len(response.content.decode()))